<?php
error_reporting(0);
$isadmin=1;
include_once '../comm/config.php';
include '../comm/msgset.php';
include 'check.php';

$ddusername = $_POST['ddusername']; 
$msg = $_POST['msg']; 
$id = $_POST['id']; 

$sj= date("Y-m-d H:i:s"); 
if($ddusername==''){
	$sql="select ddusername from ".$BIAOTOU."user";
	mysql_query("set names utf8");
	$rs = mysql_query($sql);
	while ($row = mysql_fetch_array($rs)){
		$qr = "insert into ".$BIAOTOU."msg (title,content,addtime,see,ddusername,senduser) values ('客服消息','".$msg."','".$sj."',0,'".$row['ddusername']."','网站客服')";
		mysql_query($qr);
	}
}else{
	$sql="select ddusername from ".$BIAOTOU."user where ddusername='".$ddusername."'";
	mysql_query("set names utf8");
	$rs = mysql_query($sql);
	$num=mysql_num_rows($rs);
	if($num==0){
		echo "<script language=javascript>alert('发送失败，用户名".$ddusername."不存在！');window.location='sendmsg.php'</script>";  
		exit;
	}else{	
		$qr = "insert into ".$BIAOTOU."msg (title,content,addtime,see,ddusername,senduser) values ('客服消息','".$msg."','".$sj."',0,'".$ddusername."','网站客服')";
		mysql_query($qr);
	}
}
if($id>0){
    $sql="update ".$BIAOTOU."msg set see=1 where Id=".$id;
	mysql_query($sql);
}
admin_log('发送站内信');
mysql_close();
echo "<script language=javascript>alert('成功发送 ".mysql_num_rows($rs)." 条信息！');window.location='sendmsg.php'</script>";
?>